// 用户模型
const { DataTypes } = require('sequelize');
// 数据库实例
const sequelize = require('@/config/db');
const Role = require("./role.models")
const Route = require("./route.models")

/**
 * 角色路由关联表
 */

const RoleRoute = sequelize.define('RoleRoute', {
  roleId: {
    type: DataTypes.INTEGER,
    references: {
      model: Role,
      key: 'id'
    }
  },
  routeId: {
    type: DataTypes.INTEGER,
    references: {
      model: Route,
      key: 'id'
    }
  }
}, {
  // 其他模型选项
  timestamps: true, // 自动管理创建时间和更新时间
  // paranoid: true,   // 启用软删除支持
  tableName: 'RoleRoute' // 表名
})

// 关联
Role.belongsToMany(Route, { through: RoleRoute, foreignKey: 'roleId', });
Route.belongsToMany(Role, { through: RoleRoute, foreignKey: 'routeId', });

module.exports = RoleRoute;